//学科评估
<template>
  <div class="module_">
    <div class="mb8">
      <back />
      <search v-if="!noBumber" class="mt8" @clearSearch='clearSearch'>
        <el-form label-width='95px' inline autocomplete="off" class="search_box">
          <el-form-item label="被评估学科">
            <inputSearch ref="search_d" type="xueke" @onChange='searchChane($event,"discipline_id")' />
          </el-form-item>
        </el-form>
        <template slot="footer">
        </template>
      </search>
    </div>
    <el-table v-if="editHeaderList.length > 0" :data="tableData" class="flex-1" height="100%" size="medium" border highlight-current-row
      v-loading="tableLoading" stripe >
      <el-table-column align="center" show-overflow-tooltip v-for="v in editHeaderList" :key="v.prop" :prop="v.prop"
        :label="v.label">
      </el-table-column>
    </el-table>
    <el-empty v-if="noBumber" :image-size="200" description="暂无数据"></el-empty>
  </div>
</template>

<script>
  import {
    Apievaluaterecord,
    ApievaluatetemplateInfo
  } from '@/api'
  import myTable from "../components/myTable.vue"

  export default {
    name: 'subject_viewResult',
    components:{
      myTable
    },
    data() {
      return {
        tableData: [],
        noBumber: false,
        pageparm: {
          page: 1,
          perPage: 20,
          total: null,
          sort_str: null,
          sort_order: 'desc',
        },
        tableLoading: false,
        editHeaderList: [],
        basisList: [{
          prop: "employees_name",
          label: "评估人",
          width: '150'
        }, {
          prop: "employees_department",
          label: "评估科室",
          width: '180'
        }, {
          prop: "discipline_name",
          label: "被评估学科",
          width: '180'
        }, {
          prop: "created_at",
          label: "评估时间",
          width: '180'
        }]
      }
    },
    created() {
      const template_id = this.$route.query.template_id
      const department_name = this.$store.state.userInfo.department
      ApievaluatetemplateInfo(template_id, {
        department_name
      }).then(res => {
        if(!res.data){
          this.noBumber = true
          return
        }
        const newArr = []
        const threeIndex = (arr) => {
          arr.forEach(item=>{
            if(item.children.length > 0){
              threeIndex(item.children)
            }else{
              newArr.push(item)
            }
          })
        }
        threeIndex(res.data.template)
        this.editHeaderList = [...this.basisList,...newArr]
      })
    },
    mounted() {
      this.getList()
    },
    methods: {
      tableSortChange(column) {
        if (column.order === "descending") {
          this.pageparm.sort_str = column.prop;
          this.pageparm.sort_order = "desc";
        } else if (column.order === "ascending") {
          this.pageparm.sort_str = column.prop;
          this.pageparm.sort_order = "asc";
        } else {
          this.pageparm.sort_str = null;
          this.pageparm.sort_order = null;
        }
        if (column.prop === 'created_at') this.pageparm.sort_str = 'evaluate_records.created_at'
        this.getList()
      },
      //搜索
      clearSearch() {
        this.$refs.search_d.clear()
      },
      searchChane(i, val) {
        this.pageparm[val] = i
        this.pageparm.page = 1
        this.getList()
      },
      //分页
      callFather(pageparm) {
        this.pageparm.page = pageparm.page
        this.pageparm.perPage = pageparm.perPage
        this.getList()
      },
      getList() {
        this.tableLoading = true
        this.pageparm.employees_id = this.$store.state.userInfo.employees_id
        this.pageparm.id = this.$route.query.id || null
        this.pageparm.year = this.$route.query.year || null
        Apievaluaterecord(this.pageparm).then(({
          data,
          page
        }) => {
          this.tableData = data || []
          this.pageparm.total = page.total
          this.tableLoading = false
        }).catch(() => {
          this.tableLoading = false
        })
      },
    },

  }
</script>
<style lang='less' scoped>
</style>